/** model */
import i18n from '@src/locales';
import { uuid } from '@src/util/lang/string';
/* utils */
import { GetCommonDefaultLang} from '@src/util/languages.js';

import { getCommonDefaultLangForKey } from '@hooks/useFormMultiLanguage';
import { FlowEnum, FlowNodeTranslateKeyMap } from '@model/enum/FlowEnum';

export type NodeType = `${FlowEnum}` | 'custom';

export default class Node {
  // 节点id
  public id?: string;

  public desc?: string;
  
  public type?: string;

  public title?: string;

  public icon?: string;

  public targetId?: string | null | undefined;

  public isCommon?: number;

  public isSystem?: number;
  // 自定义数据
  public data?: any = null;

  public nodeList?: Array<Node>;

  public children?: Array<Node>;

  static generateNewNode(type: NodeType, {
    id = '',
    type: customType = <NodeType>FlowEnum.NORMAL,
    title = '',
    data = {},
    targetId = '',
    icon = '', 
    isCommon = 0,
    isSystem = 0, 
    children = <Array<Node>> [],
    nodeList = <Array<Node>> []
  }): Node {
    const currentNodeName = title || FlowNodeTranslateKeyMap[type];
    return {
      id: id ? id : uuid(),
      type,
      title: currentNodeName,
      icon,
      isCommon,
      isSystem,
      data,
      targetId,
      children,
      nodeList
    };
  }
}